<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>游戏中的物理学-带摩擦力滚动的小球</title>
<script type="text/javascript" src="../lufylegend-1.7.1.min.js"></script>
</head>
<body>
<div id="mylegend"></div>
<script type="text/javascript">
	init(10,"mylegend",600,400,main);
	var backLayer;
	var EARTH = 380;
	var g = 9.8*0.01;
	var fE = 0.5;
	var ball;
	var KEY = {LEFT:37,RIGHT:39,UP:38,DOWN:40};
	var DIRECTION = {RIGHT:"right",LEFT:"left",UP:"up",DOWN:"down"};
	var STEP = 2;
	function main(){
		LGlobal.setDebug(true);
		backLayer = new LSprite();
		backLayer.graphics.drawRect(0,"black",[0,0,LGlobal.width,LGlobal.height],true,"black");
		backLayer.graphics.drawRect(0,"#660000",[0,EARTH,LGlobal.width,LGlobal.height-EARTH],true,"#660000");
		addChild(backLayer);
		addBall();
	}
	function addBall(){
		ball = new Ball();
		ball.x = 100;
		ball.y = EARTH - ball.r;
		ball.v = 1;
		ball.awake = true;
		backLayer.addChild(ball);
	}
	function Ball(){
		var self = this;
		base(self,LSprite,[]);
		self.r = 10;
		self.graphics.drawArc(1,"gray",[0,0,self.r,0,2*Math.PI],true,"gray");
		self.graphics.drawArc(1,"white",[5,-3,2,0,2*Math.PI],true,"white");
		self.direction = null;
		self.v = 0;
		self.m = 1;
		self.f = 0.002;
		self.awake = false;
		self.addEventListener(LEvent.ENTER_FRAME,self.onframe);
	}
	Ball.prototype.onframe = function (self){
		if(!self.awake)return;
		if(self.v > 0){
			var a = self.f/self.m
			if(self.v < a){
				self.awake = false;
				return;
			}
			self.v -= a;
			self.rotate += (360*self.v/(2*Math.PI*self.r));
			self.x += self.v;
		}else{
			self.awake = false;
		}
	}
</script>
</body>
</html>
